package ch.didierviret.memgest.shared.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Version;

import com.google.appengine.api.datastore.Key;

@SuppressWarnings("serial")
@Entity
public class Home implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Key key;

	@Version
	private int version;

	//Persons who live in this house
	@OneToMany(mappedBy = "home", cascade = CascadeType.ALL)
	private List<Person> persons = new ArrayList<Person>();

	private String addressLine1;
	private String addressLine2;
	private String postalCode;
	private String city;
	private String country;
	private String fixedPhone;
	private String fax;

	public Home() {
		super();
	}

	public Home(String addressLine1, String addressLine2, String postalCode,
			String city, String country, String fixedPhone, String fax) {
		super();
		this.addressLine1 = addressLine1;
		this.addressLine2 = addressLine2;
		this.postalCode = postalCode;
		this.city = city;
		this.country = country;
		this.fixedPhone = fixedPhone;
		this.fax = fax;
	}

	// TODO Test method, to be deleted
	public String toString() {
		String myString;

		if (this.key != null) {
			myString = Long.toString(key.getId());
		} else {
			myString = "";
		}
		myString += ", " + Integer.toString(getVersion());
		myString += ", " + getAddressLine1() + ", " + getAddressLine2() + ", "
				+ getPostalCode() + ", " + getCity() + ", " + getCountry()
				+ ", " + getFixedPhone() + ", " + getFax();

		return myString;
	}

	public List<Person> getPersons() {
		return persons;
	}

	public void setPersons(List<Person> persons) {
		this.persons = persons;
	}

	public String getAddressLine1() {
		return addressLine1;
	}

	public void setAddressLine1(String addressLine1) {
		this.addressLine1 = addressLine1;
	}

	public String getAddressLine2() {
		return addressLine2;
	}

	public void setAddressLine2(String addressLine2) {
		this.addressLine2 = addressLine2;
	}

	public String getPostalCode() {
		return postalCode;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getFixedPhone() {
		return fixedPhone;
	}

	public void setFixedPhone(String fixedPhone) {
		this.fixedPhone = fixedPhone;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public int getVersion() {
		return version;
	}

}
